Passed
Branch master (45a946)
by Dongxin
01:25
created

renovate.js ➔ onRenovate   C

Complexity

Conditions 7
Paths 2

Size

Total Lines 45

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 2
Metric Value
cc 7
c 4
b 0
f 2
nc 2
nop 1
dl 0
loc 45
rs 6.7272
1
// Copyright © 2017 TangDongxin
2
//
3
// Permission is hereby granted, free of charge, to any person obtaining
4
// A copy of this software and associated documentation files (the "Software"),
5
// To deal in the Software without restriction, including without limitation
6
// The rights to use, copy, modify, merge, publish, distribute, sublicense,
7
// And/or sell copies of the Software, and to permit persons to whom the
8
// Software is furnished to do so, subject to the following conditions:
9
//
10
// The above copyright notice and this permission notice shall be included
11
// In all copies or substantial portions of the Software.
12
//
13
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
15
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
17
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
18
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
19
// OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
21
// ===========================================
22
// JSON RENOVATER
23
// ===========================================
24
25
26
function onRenovate (result) {
27
28
  if (dontBeatify) {
29
30
    return;
31
32
  }
33
34
  const css = 'color:#666; cursor:pointer;';
35
  const items = document.getElementsByClassName(`S${RAND}`);
36
37
  for (let i = 0; i < items.length; i++) {
38
39
    if (isJSON(items[i].innerHTML)) {
40
41
      items[i].setAttribute('json', items[i].innerHTML);
42
      items[i].setAttribute('content', `<str style="${ css }"> [← str →]  </str><json style="${ css }"> [← json →]  </json>${ items[i].innerHTML.substring(0, 10) } ··· ${ items[i].innerHTML.substr(-10, 10)}`);
43
      items[i].innerHTML = `<str style="${ css }"> [→ str ←]  </str><json style="${ css }"> [← json →]  </json>${ items[i].innerHTML}`;
44
45
    } else if (items[i].innerHTML.length > strLength) {
46
47
48
      items[i].setAttribute('content', `<str style="${ css }"> [← str →]  </str>${ items[i].innerHTML.substring(0, 10) } ··· ${ items[i].innerHTML.substr(-10, 10)}`);
49
      items[i].innerHTML = `<str style="${ css }"> [→ str ←]  </str>${ items[i].innerHTML}`;
50
51
    } else if (isLink(items[i].innerHTML)) {
52
53
      items[i].setAttribute('url', eval(items[i].innerHTML));
54
      items[i].setAttribute('content', `<str style="${ css }"> [← str →]  </str><url style="${ css }"> [← url →]  </url> ${ items[i].innerHTML.substring(0, 10) } ··· ${ items[i].innerHTML.substr(-10, 10)}`);
55
      items[i].innerHTML = `<str style="${ css }"> [→ str ←]  </str><url style="${ css }"> [← url →]  </url>${ items[i].innerHTML}`;
56
57
    } else if(isBASE64(items[i].innerHTML)) {
58
59
      continue;
60
      // TODO to support BASE64
61
      dlog(items[i]);
62
      items[i].setAttribute('base64', items[i].innerHTML);
63
      items[i].setAttribute('content', `<str style="${ css }"> [← str →]  </str><base64 style="${ css }"> [← base64 →]  </base64>${ items[i].innerHTML.substring(0, 10) } ··· ${ items[i].innerHTML.substr(-10, 10)}`);
64
      items[i].innerHTML = `<str style="${ css }"> [→ str ←]  </str><base64 style="${ css }"> [← base64 →]  </base64>${ items[i].innerHTML}`;
65
66
    }
67
68
  }
69
70
}
71